package com.infocollect.project.api.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.infocollect.project.api.entity.TappProcessChartEntity;
import com.infocollect.project.api.entity.TappProcessEntity;
import com.infocollect.project.api.mapper.TappFromMapper;
import com.infocollect.project.api.mapper.TappProcessChartMapper;
import com.infocollect.project.api.mapper.TappProcessMapper;
import com.infocollect.project.api.service.ITappProcessChartService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (TappProcesschart)表服务实现类
 *
 * @author makejava
 * @since 2019-12-25 10:32:30
 */
@Service("tappProcesschartService")
public class TappProcessChartServiceImpl extends ServiceImpl<TappProcessChartMapper, TappProcessChartEntity> implements ITappProcessChartService {

    @Resource
    private TappFromMapper tappFromDao;
    @Resource
    private TappProcessMapper tappProcessDao;
    /**
     * 通过ID查询单条数据
     *
     * @param fid 主键
     * @return 实例对象
     */
    @Override
    public TappProcessChartEntity queryById(Long fid) {
        return this.baseMapper.queryById(fid);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit 查询条数
     * @return 对象列表
     */
    @Override
    public List<TappProcessChartEntity> queryAllByLimit(int offset, int limit) {
        return this.baseMapper.queryAllByLimit(offset, limit);
    }

    /**
     * 新增数据
     *
     * @param tappProcesschart 实例对象
     * @return 实例对象
     */
    @Override
    public TappProcessChartEntity insert(TappProcessChartEntity tappProcesschart) {
        this.baseMapper.insert(tappProcesschart);
        return tappProcesschart;
    }

    /**
     * 修改数据
     *
     * @param tappProcesschart 实例对象
     * @return 实例对象
     */
    @Override
    public TappProcessChartEntity update(TappProcessChartEntity tappProcesschart) {
        this.baseMapper.updateById(tappProcesschart);
        return this.queryById(tappProcesschart.getFid());
    }

    /**
     * 通过主键删除数据
     *
     * @param fid 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long fid) {
        return this.baseMapper.deleteById(fid) > 0;
    }

    /**
     * 查询多条数据
     * @menu 根据实体对象是否有值 进行查询
     * @return 对象列表
     */
    @Override
    public List<TappProcessChartEntity> queryAll(TappProcessChartEntity entity){
        return this.baseMapper.queryAll(entity) ;
    }

    /**
     * 根据流程模板ID 获取对应流程模板
     * @param processid
     * @return
     */
    @Override
    public Map<String,String>  queryProcessFlowChartByProcessId(Long processid){
      String pageControlstr=  tappFromDao.GetPageControl(processid);
       TappProcessEntity tappProcess= tappProcessDao.queryById(processid);
        TappProcessChartEntity tappProcesschart=   this.baseMapper.queryByProcessId(processid) ;
        Map<String,String> mapdata=new HashMap<>();
        mapdata.put("PageControl",pageControlstr);
        mapdata.put("ProcessState",tappProcess.getFstate().toString());
        mapdata.put("fprocesschart",tappProcesschart.getFprocesschart());
        mapdata.put("flowdata",tappProcesschart.getFlowdata());
        return mapdata;
    }

    @Override
    public TappProcessChartEntity  queryByProcessId(Long processid){
     return  this.baseMapper.queryByProcessId(processid) ;
    }
}